package com.qingzhu.dao.impl;

import com.qingzhu.dao.LoginDao;
import com.qingzhu.pojo.Login;
import com.qingzhu.pojo.User;
import com.qingzhu.util.CreateSqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

public class LoginDaoImpl implements LoginDao {

    @Override
    public int insertLogin(Login login) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            LoginDao loginDao = sqlSession.getMapper(LoginDao.class);
            return loginDao.insertLogin(login);
        }
    }

    @Override
    public Login login(String phone) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            LoginDao loginDao = sqlSession.getMapper(LoginDao.class);
            return loginDao.login(phone);
        }
    }

    @Override
    public Login loginFromUserId(int userId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            LoginDao loginDao = sqlSession.getMapper(LoginDao.class);
            return loginDao.loginFromUserId(userId);
        }
    }

    @Override
    public int updateLock(Login login) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            LoginDao loginDao = sqlSession.getMapper(LoginDao.class);
            return loginDao.updateLock(login);
        }
    }
}
